home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / arphdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  1.3 KB  |  61 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "arp.h"
  4.  
  5. /* Copy a host format arp structure into mbuf for transmission */
  6. struct mbuf *
  7. htonarp(arp)
  8. register struct arp *arp;
  9. {
  10.     struct mbuf *bp;
  11.     register char *buf;
  12.  
  13.     if(arp == (struct arp *)NULL)
  14.         return NULLBUF;
  15.     if((bp = alloc_mbuf(sizeof(struct arp))) == NULLBUF)
  16.         return NULLBUF;
  17.  
  18.     buf = bp->data;
  19.  
  20.     buf = put16(buf,arp->hardware);
  21.     buf = put16(buf,arp->protocol);
  22.     *buf++ = arp->hwalen;
  23.     *buf++ = arp->pralen;
  24.     buf = put16(buf,arp->opcode);
  25.     memcpy(buf,arp->shwaddr,(int16)uchar(arp->hwalen));
  26.     buf += arp->hwalen;
  27.     buf = put32(buf,arp->sprotaddr);
  28.     memcpy(buf,arp->thwaddr,(int16)uchar(arp->hwalen));
  29.     buf += arp->hwalen;
  30.     buf = put32(buf,arp->tprotaddr);
  31.  
  32.     bp->cnt = buf - bp->data;
  33.     return bp;
  34. }
  35. /* Convert an incoming ARP packet into a host-format structure */
  36. int
  37. ntoharp(arp,bpp)
  38. register struct arp *arp;
  39. struct mbuf **bpp;
  40. {
  41.     if(arp == (struct arp *)NULL || bpp == NULLBUFP)
  42.         return -1;
  43.  
  44.     arp->hardware = pull16(bpp);
  45.     arp->protocol = pull16(bpp);
  46.     arp->hwalen = pullchar(bpp);
  47.     arp->pralen = pullchar(bpp);
  48.     arp->opcode = pull16(bpp);
  49.     pullup(bpp,arp->shwaddr,(int16)uchar(arp->hwalen));
  50.     arp->sprotaddr = pull32(bpp);
  51.     pullup(bpp,arp->thwaddr,(int16)uchar(arp->hwalen));
  52.  
  53.     arp->tprotaddr = pull32(bpp);
  54.  
  55.     /* Get rid of anything left over */
  56.     free_p(*bpp);
  57.     *bpp = NULLBUF;
  58.     return 0;
  59. }
  60.  
  61.